package adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.boboqi.test.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by pc on 2017/2/24.
 */

public class MyListAdapter extends BaseAdapter {

    List<String> list = new ArrayList<>();
    Context context;

    public MyListAdapter(Context context) {
        this.context = context;
    }

    public void setData(List mlist) {
        list = mlist;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.activity_list_item, parent, false);
            holder = new ViewHolder();
            holder.tv_name = (TextView) convertView.findViewById(R.id.tv_name);
            convertView.setTag(holder);
        }
        holder = (ViewHolder) convertView.getTag();
        holder.tv_name.setText(list.get(position));
        return convertView;
    }

    public class ViewHolder {
        public TextView tv_name;
    }
}
